package org.jseda.queue.impl;

import java.util.LinkedList;

import org.jseda.queue.Queue;


public class MemoryQueueImpl<T> implements Queue<T>
{
  private LinkedList<T> _queue = new LinkedList<T>();

  /**
   * @see Queue#isEmpty().
   */
  public boolean isEmpty()
  {
    return _queue.isEmpty();
  }

  /**
   * @see Queue#size().
   */
  public int size()
  {
    return _queue.size();
  }

  /**
   * @see Queue#pushBack().
   */
  public synchronized void pushBack(T element)
  {
    if (null != element)
      _queue.addLast(element);
  }

  /**
   * @see Queue#popFront().
   */
  public synchronized T popFront()
  {
    if (_queue.isEmpty())
      return null;

    T element = _queue.getFirst();
    _queue.removeFirst();

    return element;
  }
}
